home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
207_01
/
checkc.c
< prev
next >
Wrap
Text File
|
1980-01-01
|
22KB
|
709 lines
/* checkc.c -- 4th source file for check register program */
/* copyright (c) 1986 by Jim Woolley and WoolleyWare, San Jose, CA */
/* vers. 1.0, 12/85 thru 5/86
*/
/* this file contains:
* putcursor( i, f)
* cursorput( i, c)
* cursorto( r, c)
* putpos( i)
* puttitle()
* disheading()
* recheading( s1, s2)
* putquery()
* prompt( s)
* char putcommand( c)
* char putcntrl( c)
* char putnext()
* addmoney( m3, m1, m2, add)
* movmoney( m2, m1, credit)
* putmoney( m)
* putdate( d)
* formatd( s, n, d)
* printd( d)
* sign( i)
* char witch( c)
* iscntrl( c)
* waitesc()
* waitkey()
* done()
* saveclr()
* savedat()
* calcbbf()
* char help()
* abort( s1, s2)
* aexit()
*/
#include "a:checks.h"
putcursor( i, f) /* put cursor in entry i, field f */
int i, f;
{
if ( f == PAYFIELD)
Character = min( Character, strlen( Entry[ i].payee));
else Character = 0;
cursorto(( i - First + HEAD), ( Ftoc[ f] + Character));
}
cursorput( i, c) /* put cursor in entry i, column c */
int i, c;
{
cursorto(( i - First + HEAD), c);
}
cursorto( r, c) /* put cursor at row r, column c */
int r, c; /* 0, 0 is upper-left corner */
{
int i;
if ( Printing)
putchar( '\n');
else
{
r += Linoff; /* add offset */
c += Coloff;
if ( Cb4flg)
{
i = r; /* swap */
r = c;
c = i;
}
putscr( Clead1);
putpos( r);
putscr( Clead2);
putpos( c);
putscr( Ctrail);
}
}
putpos( i) /* send cursor position i */
int i; /* ( 0 + offset) is home */
{
char *p, s[ 4];
if ( Ascur) /* if ASCII wanted */
{
strcpy(( p = s), "000"); /* template */
if ( Ascur < 3)
++p;
formatd( p, Ascur, i);
puts( p);
}
else putchar( i);
}
puttitle()
{
char f[ FNAMSIZE];
int i, length;
strcpy( f, Filename);
*( index( f, '.')) = '\0'; /* truncate at dot */
/* display 5 spaces on left, right justify f on column (COLS - 1), precede
* f with 2 spaces, then center Title in the remaining area; i.e.,
* _____<<<<<<<<<<<<<<<<<<<<<<< center Title >>>>>>>>>>>>>>>>>>>>>__A:FILENAME
*/
length = strlen( Title);
i = 5 + (( COLS - FNAMSIZE - 3) - length)/2;
length += i;
while ( i--) /* center title */
putchar( ' ');
puts( Title);
i = ( COLS - 1) - length - strlen( f);
while ( i--) /* fill title line (with Ivon) */
putchar( ' ');
puts( f);
i = HEAD - 2;
while ( i--)
putchar( '\n');
}
disheading() /* display heading for display() */
{
if ( !Printing)
{
cursorto( 0, 0);
putscr( Ivon);
}
puttitle();
puts(
" Date Payee C Amount DEP CLR Balance"
);
putchar( '\n');
puts(
"-------- ------------------------------------------ - -------- --- --- --------"
);
if ( !Printing)
putscr( Ivoff);
}
recheading( s1, s2) /* display heading for reconcile() */
char *s1, *s2;
{
if ( !Printing)
{
clrscr();
putscr( Ivon);
}
puttitle();
puts(
" Last Balance _____ Cleared Entries ______ _______ All Entries ________"
);
putchar( '\n');
puts(
" Date C Forward Checks Deposits Balance Checks Deposits Balance"
);
putchar( '\n');
puts( s1);
puts( s2);
if ( !Printing)
putscr( Ivoff);
}
putquery() /* select and display query */
{
char test, cwitch, dep;
if ( Recno > Maxentry)
{
prompt( "Press RETURN to start a new entry, or ^J for help");
return;
}
if ( isibbf( Recno)) /* if a BBF entry */
{
prompt( "Do you wish to void this entry's status as ");
puts( BBF);
puts( " (Y/N)? N");
return;
}
test = ( Field == Oldfield);
cwitch = Field;
if ( test && cwitch != DEPFIELD && cwitch != CLRFIELD)
return;
switch ( cwitch)
{
case MMFIELD:
prompt( "Enter month");
break;
case DDFIELD:
prompt( "Enter date");
break;
case YYFIELD:
prompt( "Enter year");
break;
case PAYFIELD:
prompt( "Enter/edit payee ( INSERT ");
puts( Inserton ? "ON )" : "OFF )");
break;
case CATFIELD:
prompt( "Enter category");
break;
case AMTFIELD:
prompt( "Enter/calculate amount");
cursorto(( HEAD - 4), ( AMTCOL - 9));
puts( "MEMORY = ");
putmoney( &Memory);
break;
case DEPFIELD:
prompt( "Is entry a deposit (Y/N)? ");
dep = Entry[ Recno].deposit;
goto yesno;
case CLRFIELD:
prompt( "Has entry cleared the bank (Y/N)? ");
dep = Entry[ Recno].clear;
yesno: putchar( dep ? 'Y' : 'N');
break;
}
return;
}
prompt( s) /* prompt for entry */
char *s;
{
int c;
cursorto(( HEAD - 4), 0);
puts( s);
clreol( c = strlen( s));
if ( !( *Eraeol)) /* if no Eraeol string */
cursorto(( HEAD - 4), c); /* return cursor */
Oldfield = -1;
}
char putcommand( c) /* display command */
char c; /* return TRUE if cursor moved */
{
switch ( c)
{
case CTRLK: case CTRLQ: case CTRLC: case CTRLR:
case CTRLB: case CTRLO: case CTRLP:
cursorto( 0, 0);
putscr( Ivon);
puts( CLRCOM);
putchar( '\r');
putcntrl( c);
putscr( Ivoff);
return ( TRUE);
default:
return ( FALSE);
}
}
char putcntrl( c) /* display control char */
char c; /* return ( c + CTRLTOA) or DEL */
{
if ( c != DEL)
{
putchar( '^');
putchar( c += CTRLTOA);
}
else puts( "DEL");
return ( c);
}
char putnext() /* display next command character */
{ /* return upper case character */
char c;
putscr( Ivon);
if ( isprint( c = getchar()))
{
putchar( c);
c = toupper( c);
}
else c = putcntrl( c);
putscr( Ivoff);
return ( c);
}
addmoney( m3, m1, m2, add) /* get m3 = m1 + m2 if add = TRUE */
struct money *m3, *m1, *m2; /* get m3 = m1 - m2 if add = FALSE */
char add;
{
int d, c, sd;
if ( add)
{
d = m1->dollar + m2->dollar;
c = m1->cent + m2->cent;
}
else
{
d = m1->dollar - m2->dollar;
c = m1->cent - m2->cent;
}
if ( d && ( sd = sign( d)) != sign( c))
{
d -= sd;
if ( sd < 0)
c -= 10000;
else c += 10000;
}
m3->dollar = d + c/10000;
m3->cent = c%10000;
}
movmoney( m2, m1, credit) /* set m2 = m1 if credit = TRUE */
struct money *m2, *m1; /* else, set m2 =